package com.lzh.others.Thread.class_01;

import org.apache.poi.ss.formula.functions.T;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 原子性问题：一次或多次操作中，某个操作不被其他操作干扰，要么全部执行，要么全部不执行。
 */
public class Parc_02 {
    private static int number = 0;

    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = () -> {
            for (int i = 0; i < 1000; i++) {
                number++;
            }
        };
        List<Thread> list = new ArrayList<>();
        // 使用5个线程
        for (int i = 0; i < 5; i++) {
            Thread thread = new Thread(runnable);
            thread.start();
            list.add(thread);
        }

        for (Thread thread : list) {
            thread.join();
        }

        System.out.println("number = " + number);
    }
}
